home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / vgl20.zip / KEYDEMO.C < prev    next >
C/C++ Source or Header  |  1993-05-14  |  2KB  |  54 lines

  1. /*****************************************************************************
  2.  KEYDEMO.C
  3.  
  4.  Demo program that shows how to use the VGL keyboard trapping routines.  This
  5.  one simply displays a textual description of which of the 4 arrow keys are
  6.  currently being held down.  Sorry it hasn't got a pretty display, but at
  7.  least you get the idea... I hope.
  8.  
  9.  You can add additional keys to be trapped by editing the file VGLKEY.C and
  10.  inserting or deleting them from the list.
  11.  
  12.  Mark
  13.  morley@camosun.bc.ca
  14. *****************************************************************************/
  15.  
  16. #include "vgl.h"
  17.  
  18. main()
  19. {
  20.    int i;
  21.  
  22.    clrscr();
  23.    gotoxy( 1, 1 );
  24.    cprintf( "Key Trapping Demo - Play with the arrow keys." );
  25.  
  26.    vglTrapKeys();                       /* Turn on key trapping             */
  27.  
  28.    while( !kbhit() )                    /* Loop until ESCAPE is hit         */
  29.    {
  30.       gotoxy( 1, 3 );                   /* Display the status bytes         */
  31.       for( i = 0; i < VGL_NUMKEYS; i++ )
  32.          if( vglKeyStatus[i] )
  33.             putch( '*' );
  34.          else
  35.             putch( '-' );
  36.  
  37.       gotoxy( 1, 5 );                   /* Display a message                */
  38.       if( vglKeyStatus[0] )
  39.          cprintf( "UP-ARROW " );
  40.       if( vglKeyStatus[1] )
  41.          cprintf( "DOWN-ARROW " );
  42.       if( vglKeyStatus[2] )
  43.          cprintf( "LEFT-ARROW " );
  44.       if( vglKeyStatus[3] )
  45.          cprintf( "RIGHT-ARROW " );
  46.       clreol();
  47.  
  48.       delay( 100 );                     /* Keeps cursor from flickering all */
  49.                                         /* over the place.                  */
  50.    }
  51.  
  52.    vglReleaseKeys();                    /* Disable keytrapping              */
  53. }
  54.